package com.yanqu.road.server.cmd.activity.flowerstudy.fromcross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FlowerStudyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.flowerstudy.FlowerStudyModule;
import com.yanqu.road.server.manger.activity.flowerstudy.FlowerStudyMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_FLOWER_STUDY_CROSS_SEND_RANK_TO_GAME,desc = "跨服一考到底排行榜同步到本服更新")
public class FlowerStudyExamRankUpdateCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        FlowerStudyProto.syncStudyExamRankToGameReq rankToGameReq = FlowerStudyProto.syncStudyExamRankToGameReq.parseFrom(packet.getBytes());
        long userId = rankToGameReq.getUserId();
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(userId);
        if (onlinePlayer != null){
            onlinePlayer.getModule(FlowerStudyModule.class).updateRank(rankToGameReq.getData());
        }else {
            FlowerStudyMgr.updateOffLineUserRank(rankToGameReq.getUserId(),rankToGameReq.getData());
        }

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
